pingpong is package{
  -- test the use of mail boxes to have a non-stack based ping/pong
  
  import mbox;
  
  type talker is alias of actor of {ear has type stream of string};
  
  chatty has type (()=>talker)=>talker;
  chatty(Who) is actor{
    private var lifeTime := 1000;
    Bx has type mbox of string;
    private Bx is box();
    private H is spawn{
      while true do{
        Msg is Bx.grab();
        notify Who() with Msg on ear;
      }
    };
    
    on Msg on ear do{
      logMsg(info,"I hear #Msg");
      if lifeTime>0 then {
        lifeTime := lifeTime-1;
        Bx.post(Msg);
      }
    };
  };
 
  main() do {
    let{
      ping is memo chatty(pong);
      pong is memo chatty(ping);
    } in {notify ping() with "hello" on ear};
    sleep(1000l);
  }
}
  
  